package com.jrx.anytxn.transaction.job.chargeoffProcess.step;

import com.jrx.anytxn.transaction.bean.ChargeoffPaymentBean;
import com.jrx.anytxn.transaction.mapper.ext.ExtTlPaymentLogMapper;
import com.jrx.anytxn.transaction.mapper.ext.ExtTlPaymentMappingMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ChargeoffPaymentWriter implements ItemWriter<ChargeoffPaymentBean> {

    @Resource
    private ExtTlPaymentLogMapper extTlPaymentLogMapper;
    @Resource
    private ExtTlPaymentMappingMapper extTlPaymentMappingMapper;

    @Override
    public void write(List<? extends ChargeoffPaymentBean> list) throws Exception {
        if(CollectionUtils.isNotEmpty(list)){
            for(ChargeoffPaymentBean bean : list){
                extTlPaymentLogMapper.batchInsert(bean.getSaveTlPaymentLogList());
                extTlPaymentMappingMapper.batchInsert(bean.getSaveTlPaymentMapping());
            }
        }
    }
}
